﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xiaov.SmartWeb.Model;
using Xiaov.SmartWeb.Infrastructure.ExtMethod;
using Xiaov.SmartWeb.Model.Statistical;
using System.IO;
using AjaxPro;
using Xiaov.SmartWeb.Model.ActiveRecord;
using System.Text.RegularExpressions;
using System.Reflection;
using Xiaov.SmartWeb.Model.Statistical.Select;

namespace Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem.OGWell
{
    public partial class Edit:BasePage
    {
        BaseReport Report { get; set; }

        string dwbm { get; set; }
        string year { get; set; }
        string month { get; set; }
        string tn { get; set; }



        protected void Page_Load(object sender, EventArgs e)
        {
            PM_Filter_Statistical();
            if (!IsPostBack)
            {
                //优先路径传参
                tn = Request.QueryString["tn"].ToRequestString().ToUpper();                    
                //加载参数                 
                dwbm = Request.QueryString["dwbm"].ToRequestString().ToUpper();
                year = Request.QueryString["year"].ToRequestString();
                month = Request.QueryString["month"].ToRequestString();
                //如果没有路径参数 
                //如果没有表名 终止
                if (string.IsNullOrEmpty(tn))
                    Xiaov.SmartWeb.Infrastructure.Common.General.ShowAlert("错误的参数");

                //如果没有URL传参 则设置默认值
                if (string.IsNullOrEmpty(dwbm))
                {
                    //优先使用cookies
                    if (Request.Cookies["UserSelectInfo"] != null)
                        dwbm = Request.Cookies["UserSelectInfo"]["DW"].ToRequestString();
                    else
                        //没有cookie使用用户默认单位  没有防止用户篡改cookies
                        dwbm = PUser.USERDEPT;
                }

                if (string.IsNullOrEmpty(year))
                {
                    //优先使用cookies
                    if (Request.Cookies["UserSelectInfo"] != null)
                        year = Request.Cookies["UserSelectInfo"]["NF"].ToRequestString();
                    else
                        year = DateTime.Now.AddMonths(-1).Year.ToString();
                }
                if (string.IsNullOrEmpty(month))
                {
                    //优先使用cookies
                    if (Request.Cookies["UserSelectInfo"] != null)
                        month = Request.Cookies["UserSelectInfo"]["YF"].ToRequestString();
                    else
                        month = DateTime.Now.AddMonths(-1).Month.ToString();
                }

                if (string.IsNullOrEmpty(tn))
                    Xiaov.SmartWeb.Infrastructure.Common.General.ShowAlert("错误的参数");
                
               
                //初始化配置
                Report = new BaseReport(tn, dwbm, year, month);
                Report.ReSetParmas(dwbm, tn, year, month, PUser.USERDEPT);
                Report.URI = this.Request.Url;
                Report.InitReport();
                Report.ViewUser = PUser;
                Report.Permissions = this.Permissions;                
                //报表html生成
                string html = Report.Html("/Resources/xiaovcn/templete/well.html");
                Response.Clear();
                Response.Write(html);
                Response.End();
            }
        }

        
      
    }
}